<template>
	<view>
		<image class="qr-img" :src="qrimg" mode=""></image>
		<view class="down-img" @click="downImgae">
			下载图片
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				qrimg: '', // https://wechat.shuangxitang.cn/plugins/wxapp/assets/temp/45f8b4e507ad03c6809c9249866c5f12.jpg
				id: 0
			}
		},
		onLoad(options) {
			// console.log(options);
			this.id = options.id
			this.generateqr(options.id)
			uni.showShareMenu({
				withShareTicket: true,
				menus: ['shareAppMessage']
			})
		},
		onShareAppMessage() {
			return {
				title: '绑定',
				path: '/plugins/mch_solitaire/binding/binding?id=' + this.id
			}
		},
		methods: {
			generateqr(id) {
				let qrpath = 'plugins/mch_solitaire/binding/binding'
				// qrpath = 'pages/index/index'
				this.$request({
					url: this.$api.generate.appcode,
					method: 'post',
					data: {
						path: qrpath,
						width: '750',
						scene: "id=" + id
					},
				}).then(response => {
					// console.log(response);
					if (response.code === 0) {
						this.qrimg = response.data.qrcode;
					} else {
						uni.showToast({
							title: response.msg,
							icon: 'none',
							duration: 1000,
						});
					}
				}).catch(() => {});
			},
			downImgae() {
				let self = this;
				uni.showLoading({
					title: '图片保存中'
				});
				uni.downloadFile({
					url: self.qrimg,
					success(res) {
						uni.saveImageToPhotosAlbum({
							filePath: res.tempFilePath,
							success() {
								uni.hideLoading();
								uni.showToast({
									title: '保存成功',
									duration: 3000,
									icon: 'none',
								});
							},
							fail() {
								uni.hideLoading();
								self.getAuthSetting();
							},
							complete() {}
						})
					}
				});
			}
		}
	}
</script>

<style>
	.qr-img {
		width: 750rpx;
		height: 750rpx;
	}

	.down-img {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		height: 100rpx;
		line-height: 100rpx;
		background-color: #E4432E;
		color: #fff;
		font-size: 32rpx;
		text-align: center;
		padding-bottom: 0;
		padding-bottom: constant(safe-area-inset-bottom);
		padding-bottom: env(safe-area-inset-bottom);
	}
</style>
